<template>
<div>
    <div class="search_block">
        <el-form :inline="true" :model="search" class="demo-form-inline">
            <el-form-item label="管理员">
                <el-input v-model="search.user_name" placeholder="管理员"></el-input>
            </el-form-item>
            <el-form-item label="内容">
                <el-input v-model="search.content" placeholder="内容"></el-input>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" @click="init" size="small">搜索</el-button>
            </el-form-item>
        </el-form>
    </div>
    <div class="option-block"></div>
    <div class="content">
        <el-table ref="singleTable" highlight-current-row @current-change="handleRowChange" :data="list" v-loading="loading" id="form" style="width: 100%" height="668">
            <el-table-column prop="_id" label="编号" width="230"></el-table-column>
            <el-table-column prop="user" label="管理员" width="230"></el-table-column>
            <el-table-column prop="request_path" label="请求地址" width="150"></el-table-column>
            <el-table-column prop="request_param" label="请求内容"></el-table-column>
            <el-table-column prop="request_ip" label="请求IP" width="180"></el-table-column>
            <el-table-column label="是否授权" width="100">
                <template slot-scope="scope">
                    {{ scope.row.is_permited ? '已授权' : '未授权' }}
                </template>
            </el-table-column>
            
            <el-table-column prop="created_at" label="时间" width="150"></el-table-column>
        </el-table>

        <div class="pager-block">
            <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="current_page" :page-sizes="[15, 20, 30, 50,100]" :page-size="per_page" layout="total, sizes, prev, pager, next, jumper" :total="total">
            </el-pagination>
        </div>
    </div>
</div>
</template>

<script>
export default {
    data() {
        return {
            search:{},
            loading: true,
            current_page: 1,
            per_page: 15,
            total: 0,
            list: [],
        }
    },
    mounted() {
        this.init()
    },
    methods: {
        handleRowChange(val) {
            this.selectedRow = val;
        },
        handleSizeChange(val) {
            this.per_page = val
            this.current_page = 1
            this.init()
        },
        handleCurrentChange(val) {
            this.current_page = val
            this.init()
        },
        init() {
            const _this = this
            _this.loading = true
            _this.loadList(function(res) {
                _this.list = res.data
                _this.current_page = res.current_page
                _this.per_page = parseInt(res.per_page)
                _this.total = res.total
                _this.loading = false
            })
        },
        loadList(func) {
            axios.post(basePath + '/system/log?pageSize=' + this.per_page + '&page=' + this.current_page,this.search).then(func)
        },
    }
}
</script>
